/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services.Impl;

import java.util.Collection;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import models.Baskets;
import models.ItemBasket;
import models.Orders;
import services.interfaces.IBasketService;

/**
 *
 * @author Yaroslav
 */

@Stateless
@LocalBean
public class BasketServiceImpl extends GenericServiceImpl<Baskets> implements IBasketService {

    
    @PersistenceContext(unitName="orsPU")
    private EntityManager em;
    
    public BasketServiceImpl() {
        super(Baskets.class);
    }
    
    
    
    @Override
    protected EntityManager getEntityManager() {
       return this.em;
    }

    @Override
    public Collection<Baskets> getProductByPrice(double price) {
       Query q = em.createNamedQuery("Baskets.findByPrice").setParameter("price", price);
       Collection entities = q.getResultList();
       return  entities;
    }

    @Override
    public Collection<Baskets> getProductById(Long id) {
       Query q = em.createNamedQuery("Baskets.findById").setParameter("id", id);
       Collection entities = q.getResultList();
       return  entities;
    }

    @Override
    public void addItemToBaskets(ItemBasket ib, Baskets baskets) {
        
    }
    
}
